/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


//距下边界长度/单位px
var range = 50;
//设置加载最多次数
var maxnum = 20;
var num = 1;
var totalheight = 0;
//主体元素
var list = $("#list");
var loader = $("#loading");
var nodata = $("#nodata");
var loading = false;
$(window).scroll(function () {
    //滚动条距顶部距离(页面超出窗口的高度)
    var srollPos = $(window).scrollTop();
    totalheight = parseFloat($(window).height()) + parseFloat(srollPos);
    if (($(document).height() - range) <= totalheight && num !== maxnum) {
        if (loading)
            return;
        loading = true;
        $.ajax({
            type: "GET",
            url: "test/loading",
            dataType: "html",
            //async: true,
            data: {name: "上海", page: num},
            beforeSend: function () {
                //请求前的处理
                loader.show();
            },
            success: function (data) {
                list.append(data);
                num++;
                loading = false;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var msg = 'status:' + XMLHttpRequest.status;
                msg += ' readyState:' + XMLHttpRequest.readyState;
                msg += ' textStatus:' + textStatus;
                nodata.find('.weui-loadmore__tips').html(msg);
                nodata.show();
            },
            complete: function () {
                //请求完成的处理
                loader.hide();
            }
        });
    }
});
